package com.company.vmvp.ui.main;

import android.os.Bundle;

import com.company.vmvp.R;
import com.company.vmvp.api.HttpManager;
import com.company.vmvp.base.BaseActivity;
import com.company.vmvp.tools.AppTools;
import com.dee.components.util.DataUtils;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * 作者：kkan on 2018/04/20
 * 当前类注释:
 * 欢迎页
 */
public class WelcomeActivity extends BaseActivity {

    @Override
    public int getLayoutId() {
        return R.layout.activity_welcome;
    }

    /*启用MVP一定要设置这句*/
    @Override
    public void initPresenter() {
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        swipeDragToClose();
        //设置公共参数Token
        HttpManager.getInstance().setToken(AppTools.getToken());
        mRxManager.add(Observable.timer(1500, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        goToPage();
                    }
                }));
    }

    private void goToPage() {
        userBean = AppTools.getUserBean();
        String userid = userBean.getUserId();
        //也可以判断其他  如token
//            HttpManager.getInstance().setToken(token);
        if (DataUtils.isNullString(userid)) {
            startActivityFinish(LoginActivity.class);
        } else {
            startActivityFinish(MainActivity.class);
        }
    }
}
